<div class="card card-primary">
    <div class="card-body">
        <div class="filter-panel d-none">
            <form action="" method="get" class="frm-filter">
                <div class="row">
                    <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
                        <div class="form-group row">
                            <label
                                class="col-lg-2 col-md-2 col-sm-3 col-xs-6 mb-0 pt-2 text-right">{:lang("Title")}</label>
                            <div class="col-lg-10 col-md-10 col-sm-9 col-xs-6">
                                <input type="text" class="form-control" name="name" placeholder="{:lang('Title')}"
                                    data-op="like %...%">
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
                        <div class="form-group text-start">
                            <input type="reset" class="btn btn-default" value="{:lang('Reset')}">
                            <input type="submit" class="btn btn-primary ml-2" value="{:lang('Search')}">
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div id="toolbar" class="toolbar">
            {:build_toolbar('refresh')}
            <!--<button type="button" class="btn btn-secondary btn-refresh" data-toggle="tooltip" data-placement="top" title="" data-original-title="{:lang('Reload page')}"><i class="fas fa-redo-alt"></i></button>&nbsp;-->
            {if (has_rule('add'))}
            <button type="button" class="btn btn-primary btn-add "
                data-url="{:url('/substation/add',['popup'=>1,'id'=>$parent_id])}"><i class="fas fa-plus"></i>
                {:lang('Add')}</button>&nbsp;
            {/if}
            {if (has_rule('del'))}
            <button type="button" class="btn btn-disabled btn-danger disabled btn-del"
                data-url="{:url('/substation/del')}"><i class="fas fa-trash-alt"></i>
                {:lang('Delete')}</button>
            {/if}
            {if (has_rule('batches'))}
            <div class="dropdown ml-1 btn-toggle">
                <a class="btn btn-secondary dropdown-toggle btn-disabled disabled" href="#" role="button"
                    id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <i class="fas fa-"></i> {:lang('Setting')}
                </a>
                <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
                    <a class="dropdown-item status" href="#" data-params="status=normal">{:lang('Set to enable')}</a>
                    <a class="dropdown-item status" href="#" data-params="status=hidden">{:lang('Set to disabled')}</a>
                </div>
            </div>
            {/if}
            {if $backid}
            <a href="{:url('/substation/index',['popup'=>1,'id'=>$backid])}"
                class="btn btn-success btn-add">{:lang('Parent')}</a>
            {/if}
        </div>
        {if ($backname)}
        <div class="listtitle">
            <h3>{$backname}</h3>
        </div>
        {/if}
        <table id="table" data-del="{if has_rule('del')}{:url('/Substation/del')}{/if}"
            data-batches="{if has_rule('batches')}{:url('/Substation/batches')}{/if}"></table>
    </div>
</div>

{block:script}
<script>
    require(['jquery', 'layer', 'cmsTable'], function ($, undefined, cmsTable) {
        $(function () {
            var table = cmsTable.init({
                url: "{:url('/Substation/index',['popup'=>1,'id'=>$parent_id])}",
                search: false,
                escape: false,
                sortName: 'weigh,id',
                customFilter: true,
                columns: [{
                    field: 'state',
                    checkbox: true,
                }, {
                    field: 'weigh',
                    title: '{:lang("Weigh")}',
                    formatter: cmsTable.formatter.txtEditBtn,
                    events: cmsTable.events.txtEditBtn
                }, {
                    field: 'SN',
                    title: '{:lang("Serial number")}',
                    formatter: cmsTable.formatter.SN
                }, {
                    field: 'id',
                    title: 'ID',
                }, {
                    field: 'name',
                    title: '{:lang("Title")}',
                    align: 'left',
                }, {
                    field: 'math',
                    title: '{:lang("Math")}',
                    align: 'left',
                }, {
                    field: 'new_window',
                    title: '{:lang("Recommend")}',
                    formatter: cmsTable.formatter.switchBtn,
                    events: cmsTable.events.switchBtn
                }, {
                    field: 'status',
                    title: '{:lang("Status")}',
                    formatter: cmsTable.formatter.switchBtn,
                    events: cmsTable.events.switchBtn
                }, {
                    field: 'operate',
                    title: '{:lang("Operate")}',
                    formatter: function (value, row, index) {
                        let edit_url = Util.setUrlParams({ url: '{:url("/Substation/edit")}', query: { popup: 1, id: row['id'] } });
                        let add_url = Util.setUrlParams({ url: '{:url("/Substation/index")}', query: { popup: 0, id: row['id'] } });
                        let html = '';

                        /* {if has_rule('edit')} */
                        html = '<a href="javascript:cmsOpen(\'' + edit_url + '\',\'{:lang("edit")}\')" class="btn btn-primary btn-xs text-white"><i class="fas fa-pen"></i></a>&nbsp<a href="' + add_url + '" class="btn btn-warning btn-xs text-white">{:lang("Next")}</a>&nbsp';
                        /* {/if} */

                        return html + cmsTable.formatter.operate.call(this, value, row, index)
                    },
                    events: cmsTable.events.operate
                }]
            });
        })
    })
</script>
{/block:script}